package com.yyfax.pay.depository.controller.api;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.yyfax.pay.common.util.FuiouIdUtils;
import com.yyfax.pay.depository.service.inner.ChargeInnerService;
import com.yyfax.pay.order.model.vo.PayBusiIdVO;
import com.yyfax.pay.third.model.to.fuioudeposit.ChargeNotifyReq;
import com.yyfax.pay.third.model.to.fuioudeposit.EBankChargeBackReq;
import com.yyfax.pay.third.model.to.fuioudeposit.TransferChargeBackReq;

/**
 * 充值网关同步结果通知入口
 * 
 * @author buyi
 * @date 2017-09-02 10:10:17
 * @since v2.0.0
 */
@RestController
public class ChargeResultApiController {

	@Resource
	private FuiouIdUtils fuiouIdUtils;
	@Resource
	private ChargeInnerService chargeInnerService;

	/**
	 * 网银异步返回请求入口
	 * 
	 * @author buyi
	 * @date 2017-09-02 10:38:15
	 * @since v2.0.0
	 * @param merchantCode
	 * @param req
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(method = RequestMethod.POST, path = "/api/fuiou/charge/ebank/result/back/{merchantCode}")
	public void ebankBack(@PathVariable("merchantCode") String merchantCode, EBankChargeBackReq req) {

		chargeInnerService.parseEbankBackResult(merchantCode, req);
	}

	/**
	 * 充值异步通知入口<br>
	 * 异步通知不再做为结果依据作废
	 * 
	 * @author buyi
	 * @date 2017-09-04 17:28:25
	 * @since v2.0.0
	 * @param req
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(method = RequestMethod.POST, path = "/api/fuiou/charge/result/notify")
	public String resultNotify(ChargeNotifyReq req) {
		PayBusiIdVO busiIdVO = fuiouIdUtils.parserBusiId(req.getMchnt_txn_ssn());

		return chargeInnerService.parseChargeNotifyResult(busiIdVO.getMerchantCode(), req);
	}

	/**
	 * 转账充值同步结果异步通知
	 * 
	 * @author buyi
	 * @date 2018-03-28 16:15:12
	 * @since v2.1.3
	 * @param req
	 */
	@PostMapping("/api/fuiou/charge/transfer/result/back/{merchantCode}")
	public String transferChargeBack(@PathVariable("merchantCode") String merchantCode, TransferChargeBackReq req) {
		chargeInnerService.parseTransferBackResult(merchantCode, req);
		return "d";
	}

}
